package model

import (
	"gorm.io/gorm"
	"jsjb/connect"
)

type User struct {
	Id         int32  `json:"id"`
	Username   string `json:"username"`
	Password   string `json:"password"`
	Realname   string `json:"realname"`
	Telphone   string `json:"telphone"`
	Salt       string `json:"salt"`
	Orgname    string `json:"orgname"`
	Orgid      string `json:"orgid"`
	Status     string `json:"status"`
	Del        string `json:"del"`
	Openid     string `json:"openid"`
	Isprimary  string `json:"isprimary"`
	Group      string `json:"group"`
	Townid     int32  `json:"townId"`
	OfficeId   string `json:"officeId"`
	OfficeName string `json:"officeName"`
	OfficeType int32  `json:"officeType"`
}

func FindUser(username string) (user *User, err error) {
	user = new(User)
	if err = connect.DB.Table("admin").Where(`username = ? and del = 0 and status = "normal"`, username).Find(&user).Error; err != nil {
		return nil, err
	}

	return
}

// AfterFind 查询后的钩子
func (u *User) AfterFind(tx *gorm.DB) (err error) {
	//if u.MemberShip == "" {
	//	u.MemberShip = "user"
	//}
	return
}
